Class BinarySearchTree<T extends TreeNodeInfo>
- java.lang.Object
-
- edu.claflin.finder.logic.communities.struct.BinarySearchTree<T>
-
public class BinarySearchTree<T extends TreeNodeInfo> extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallow_duplicatesprivate TreeNode<T>root
-
Constructor Summary
Constructors Constructor Description BinarySearchTree()Create an empty BinarySearchTree.BinarySearchTree(boolean dup)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T info)Addd a new Tree Node with the given j index and q valueprivate voidadd(T info, TreeNode<T> p)Recursive implementation of add.booleanallows_duplicates()java.util.List<T>asList()private voidasList(java.util.List<T> l, TreeNode<T> p)voidclear()booleancontains(T info)Is the specified ElemntType in the BinarySearchTree?private booleancontains(T info, TreeNode<T> p)private voidcreateBackbone()Time complexity: O(n)private voidcreatePerfectBST()Time complexity: O(n)voidDSW()Tget(T info)private TreeNode<T>get(T info, TreeNode<T> p)intgetHeight()private intgetHeight(TreeNode<T> p)TgetMax()TgetMax(TreeNode<T> p)TgetMin()private TgetMin(TreeNode<T> p)java.lang.DoublegetVal(T info)private intgreatestPowerOf2LessThanN(int n).booleanisEmpty()Is the BinarySearchTree empty?private voidmakeRotations(int bound)voidmergeTrees(BinarySearchTree that)private voidmergeTrees(BinarySearchTree that, TreeNode<T> p)intMSB(int n)Return the index of most significant set bit: index of least significant bit is 0.voidremove(T info)private TreeNode<T>remove(T info, TreeNode<T> p)private voidrotateLeft(TreeNode<T> grandParent, TreeNode<T> parent, TreeNode<T> rightChild)private TreeNode<T>rotateRight(TreeNode<T> grandParent, TreeNode<T> parent, TreeNode<T> leftChild)voidset(T info)java.lang.StringtoString()Gets an inorder String representation of the BinarySearchTree.private java.lang.StringtoString(TreeNode<T> p)Recursive implementation of inorder toString.
-
-
-
Field Detail
-
root
private TreeNode<T extends TreeNodeInfo> root
-
allow_duplicates
private boolean allow_duplicates
-
-
Method Detail
-
allows_duplicates
public boolean allows_duplicates()
-
isEmpty
public boolean isEmpty()
Is the BinarySearchTree empty?- Returns:
- true if empty, false otherwise
-
clear
public void clear()
-
add
public void add(T info)
Addd a new Tree Node with the given j index and q value- Parameters:
info- the key
-
add
private void add(T info, TreeNode<T> p)
Recursive implementation of add.- Parameters:
info- the keyp- the current top Tree Node
-
getVal
public java.lang.Double getVal(T info)
-
set
public void set(T info)
-
contains
public boolean contains(T info)
Is the specified ElemntType in the BinarySearchTree?- Parameters:
info- the key- Returns:
- true if it is contained, false otherwise
-
toString
public java.lang.String toString()
Gets an inorder String representation of the BinarySearchTree.- Overrides:
toStringin classjava.lang.Object- Returns:
- the BinarySearchTree as a String
-
toString
private java.lang.String toString(TreeNode<T> p)
Recursive implementation of inorder toString.- Parameters:
p- the current TreeNode to print and recursive parameter- Returns:
- the BinarySearchTree as a String
-
getMin
public T getMin()
-
getMax
public T getMax()
-
remove
public void remove(T info)
-
getHeight
public int getHeight()
-
DSW
public void DSW()
-
createBackbone
private void createBackbone()
Time complexity: O(n)
-
rotateRight
private TreeNode<T> rotateRight(TreeNode<T> grandParent, TreeNode<T> parent, TreeNode<T> leftChild)
-
createPerfectBST
private void createPerfectBST()
Time complexity: O(n)
-
greatestPowerOf2LessThanN
private int greatestPowerOf2LessThanN(int n)
. Time complexity: log(n)- Parameters:
n- the inout number- Returns:
- the greatest power of 2 less than N
-
MSB
public int MSB(int n)
Return the index of most significant set bit: index of least significant bit is 0. Time complexity: log(n)- Parameters:
n- the input number- Returns:
- the index of most significant set bit
-
makeRotations
private void makeRotations(int bound)
-
rotateLeft
private void rotateLeft(TreeNode<T> grandParent, TreeNode<T> parent, TreeNode<T> rightChild)
-
mergeTrees
public void mergeTrees(BinarySearchTree that)
-
mergeTrees
private void mergeTrees(BinarySearchTree that, TreeNode<T> p)
-
asList
public java.util.List<T> asList()
-
-